package ${package.Controller};

import org.springframework.web.bind.annotation.RequestMapping;
<#if restControllerStyle>
import org.springframework.web.bind.annotation.RestController;
<#else>
import org.springframework.stereotype.Controller;
</#if>
<#if superControllerClassPackage??>
import ${superControllerClassPackage};
</#if>
import org.springframework.beans.factory.annotation.Autowired;
import ${package.Service}.${table.serviceName};
import ${package.Entity}.${table.entityName};
import org.springframework.web.bind.annotation.*;
import com.example.mybatisplusgen.utils.response.CommonResponse;

/**
 * <p>
 * ${table.comment!} 前端控制器
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
<#if restControllerStyle>
@RestController
<#else>
@Controller
</#if>
@RequestMapping("<#if package.ModuleName?? && package.ModuleName != "">/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle>${controllerMappingHyphen}<#else>${table.entityPath}</#if>")
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
<#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
<#else>
public class ${table.controllerName} {
</#if>
        @Autowired
        private ${table.serviceName} ${table.entityPath}Service;

        @PostMapping("/getList")
        public CommonResponse getList(@RequestBody ${entity} ${table.entityPath}) {
            return CommonResponse.ok(${table.entityPath}Service.select${entity}List(${table.entityPath}));
        }

        @DeleteMapping("/{id}")
        public CommonResponse deleteByID(Long id) {
            boolean b = ${table.entityPath}Service.delete${entity}(id);
            if (!b) {
            return CommonResponse.fail();
            }
            return CommonResponse.ok("删除成功");
        }

        @PostMapping("/")
        public CommonResponse insert(@RequestBody ${entity} ${table.entityPath}) {
            boolean b = ${table.entityPath}Service.insert${entity}(blogTag);
            if (!b) {
            return CommonResponse.fail();
            }
            return CommonResponse.ok("插入成功");
        }

        @PutMapping("/")
        public CommonResponse update(@RequestBody ${entity} ${table.entityPath}) {
            boolean b = ${table.entityPath}Service.update${entity}(blogTag);
            if (!b) {
            return CommonResponse.fail();
            }
            return CommonResponse.ok("更新成功");
        }
}
</#if>
